home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS2.ZIP / DOSFKEYS.TXT next >
Text File  |  1985-11-24  |  52KB  |  1,028 lines

  1.                 Defining Functions Keys with PC-DOS 2.0
  2.          (PC Magazine Vol 2 No 1 June 1983 by Kenneth W. Wood)
  3.  
  4.      PC-DOS 2.0 is packed full of new features.  One is its ability to 
  5. redefine the function of any key on the keyboard.  Most often, users 
  6. will want to redefine the ten function keys.
  7.      An item in PC-DOS 2.0 that is rarely looked at is the ANSI 
  8. terminal handler contained in the file called ANSI.SYS.  When in 
  9. memory, the ANSI terminal handler interprets special character 
  10. sequences written to the console.  Since each of these special 
  11. sequences begins with the Escape character, these are called "escape 
  12. sequences."  The Escape character (ASCII 27) is referred to as Esc.
  13.      Basically, the ANSI terminal handler defines a way of positioning 
  14. the cursor and setting certain terminal attributes.  For example, if a 
  15. program were to write the sequence "Esc[12;43f", the cursor would be 
  16. positioned at line 12 column 43.  Other sequences control blinking, 
  17. underlining, erasing to end of line, clearing the screen, etc.  Thus, 
  18. from any language (Pascal, BASIC, C, assembler, etc.) you can
  19. precisely control the appearance of the screen.  In addition, the ANSI
  20. terminal handler provides programmers with a tool for developing easily
  21. transportable software for compatible computers, regardless of the
  22. specific terminal characteristics of each computer.
  23.      The Keyboard Key Reassignment (KKR) escape sequence is of special 
  24. interest.  The KKR sequence establishes a new set of ASCII characters 
  25. that are to be issued whenever the designated key is depressed.  For 
  26. example, one could define the F1 key to be "DIR A:".  According to the 
  27. PC-DOS manual, any key on the keyboard can be reassigned, even the 
  28. QWERTY keys.  The manual, however, provides very little documentation 
  29. on the KKR sequence.  Worse, there are undocumented limitations!
  30.      Without getting too technical, PC-DOS 2.0 sets up a special area 
  31. of memory as a lookup table for each key that you redefine.  This 
  32. lookup table is limited to 128 bytes.  Thus, if you attempt to define 
  33. too many keys, or use long character sequences on too many keys, the 
  34. table size is exceeded.  If care is not taken, it will be exceeded to 
  35. the extent that PC-DOS meets its maker and you must reboot!
  36.      How do you use this new PC-DOS capability?  First of all, you must 
  37. have a file on your boot disk called CONFIG.SYS.  This file is read 
  38. automatically by PC-DOS at boot time to determine the system 
  39. configuration.  In order to define the function keys, you must have a 
  40. "DEVICE = ANSI.SYS" statement in the CONFIG.SYS file.  This statement 
  41. loads the ANSI terminal handler into memory.
  42.      Next, you must print a KKR sequence to the screen for each key to 
  43. be defined.  Since this can be tedious, I developed a special C 
  44. language program for this purpose.  This program, FUNKEY, is designed 
  45. specifically for defining the function keys F1 to F10, as well as 
  46. Shift, Ctrl, and Alt in combination with the ten function keys.  FUNKEY 
  47. accepts a list of function key definitions as input and issues the 
  48. appropriate KKR sequences as output. The program does not provide for 
  49. the arbitrary redefinition of any or all keys on the keyboard.  Sample 
  50. function key definition files are discussed in the next section.  
  51.      I created FUNKEY using the Computer Innovations, Inc. C language 
  52. compiler, CI-C86.  This is one of the few C compilers for the IBM PC 
  53. that includes all standard C language features.  FUNKEY, however, only 
  54. involves simple input and output commands, so any adequate C compiler 
  55. should be able to run this program.  Similar programs could also be 
  56. written in Pascal, BASIC or other languages.
  57.      Use of the program is straightforward.  When you type FUNKEY, the 
  58. program is loaded into memory and begins execution.  To define F3 as 
  59. "CHKDSK B:" you simply type F3=CHKDSK B: then hit Return.  After 
  60. defining the desired keys, type a Ctrl-Z and hit Return.  For a large 
  61. number of keys, this method is inconvenient.  Instead, you can type 
  62. FUNKEY FILE.KEY to have the list of function key definitions taken 
  63. from the file.  For example, the file STAR.KEY could contain a list of 
  64. function key definitions for WordStar.
  65.      This article will not concentrate on programming techniques 
  66. involved in FUNKEY.  Instead, my emphasis is upon various ways of using 
  67. the function key definition capability.  The program provided here 
  68. should be viewed as a foundation on which to build a more user-friendly 
  69. key definition program.  To increase the flexibility of the program 
  70. somewhat, each function key definition is normally terminated with a 
  71. space.  However, if you need a command to end with a carriage return, 
  72. simple use the "!" as the last character of that function key 
  73. definition.
  74.      Applications of function key definitions fall into two broad 
  75. categories: defining keys to issue commands, and defining keys with 
  76. specific strings for use in an application.  As an example for the 
  77. first category, I find that DIR, TYPE, COPY, and CHKDSK are among the 
  78. most common PC-DOS commands that I use.  The file shown in Figure 1 
  79. illustrates the set of function keys for use at the PC-DOS command 
  80. level.  By including "FUNKEY DOS.KEY" in my AUTOEXEC.BAT file, each 
  81. time I use PC-DOS all of the commands are just a function key away.
  82.      There are many ways that you can use the function keys at the PC-
  83. DOS level.  For example, one key could be set up as "CHKDSK A:", and 
  84. another as "CHKDSK B:".  However, this approach is inefficient, since 
  85. the same command appears on more than one key.  I chose to set up F1 
  86. and F2 as "A:" and "B:".  Then, by combining another command key with 
  87. either F1 of F2 I can specify either disk.  For example, typing F4 
  88. ("CHKDSK") then F2 ("B:") issues the "CHKDSK B:" command.
  89.      A few potential problems should be considered.  First of all, many 
  90. popular programs already make special use of the function keys.  The 
  91. program I principally use is The FinalWord.  All of the function keys 
  92. are already defined by this software and they can be customized with a 
  93. FinalWord utility.  The PC-DOS function key definitions, discussed 
  94. above, would override the FinalWord definitions since they are 
  95. intercepted by the operating system and passed to the program.  
  96. However, there is no documented way to clear the definitions you use.  
  97. The only method to restore the default set of key definitions is to
  98. reboot the system.
  99.      On the other hand, the fact that your definitions override 
  100. existing definitions can be a blessing as well.  Some of the choices 
  101. made by MicroPro for the PC-DOS function keys defy logic.  The key 
  102. arrangements in many other programs are equally illogical.  In some 
  103. cases, you can use the capabilities described here.  However, if a 
  104. program bypasses the normal operating system calls in order to perform 
  105. keyboard input, then the key definitions you created are also bypassed.  
  106. Such is apparently the case with WordStar, since an attempt to redefine 
  107. function keys for WordStar failed to override the existing definitions.
  108.      Finally, each key definition sequence must end with "white space" 
  109. -- that is, a blank or a carriage return.  The ANSI driver seems to use 
  110. these characters as separators between new definitions.  I tried 
  111. terminating the definitions with other characters, such as the null, 
  112. with the result that all of the key definitions ran together into one 
  113. giant sequence.  There is no problem in using this capability to define 
  114. strings.  However, some programs do not like a space or carriage return 
  115. after a sequence of control characters.
  116.      Using this capability to reset the function keys can create 
  117. another minor problem.  Suppose that you set the keys up for WordStar, 
  118. then switched to VisiCalc.  The key definitions are no longer 
  119. appropriate.  I find it annoying to constantly remind myself to switch 
  120. to the proper function key set.  The best way to painlessly use the 
  121. function keys is to write a batch file for each program.  The batch 
  122. file takes the generic form:
  123.           FUNKEY APPL.KEY
  124.           Application
  125.           FUNKEY DOS.KEY
  126.      This file loads the definitions for an application, calls the 
  127. application, and resets the keys for PC-DOS after you exit the 
  128. application.  For example, if STAR.KEY was a file of the key 
  129. definitions for WordStar, create a batch file called WORD.BAT.  Its
  130. contents would be:
  131.           FUNKEY STAR.KEY
  132.           WS
  133.           FUNKEY DOS.KEY
  134. Then call up the batch file by typing WORD rather than WS.
  135.      Another way to use the function keys is with commonly used 
  136. strings.  For example, suppose that your company name is "Federated 
  137. Software Arts and Science, Inc."  You could assign a string with the 
  138. company name to a function key.  Then, as you use your word processor, 
  139. whenever the company name is needed, you just press that function key.  
  140. Or, in writing an article for a specific subject, frequently used 
  141. lengthy terms such as "operational transconductance amplifier" can be 
  142. assigned to function keys and used as needed.  If you do this, remember 
  143. that PC-DOS restricts you to 128 characters as the total for all keys 
  144. that you define.
  145.      I am aware of at least two programs, written for use with PC-DOS 
  146. 1.0 and 1.1, that provide function key capabilities:  ProKey and 
  147. Keynote.  Both ProKey and Keynote provide many more key definition 
  148. capabilities than PC-DOS 2.0.  First of all, there is no 128-byte 
  149. restriction.  ProKey provides over 125 definable keys, and each key can 
  150. be up to 1,000 characters long.  Furthermore, key definitions can 
  151. include "fill-in-the-blank" fields and references to other defined 
  152. keys.  ProKey is memory resident, which means that you can change the 
  153. key definitions anytime while in a program.  Thus, ProKey can provide 
  154. macro-like capability.  The possibilities provided by ProKey and 
  155. Keynote are endless.
  156.      Function key redefinition is one of the new capabilities provided 
  157. by PC-DOS 2.0.  Although useful, this capability is still limited 
  158. compared to commercial programs designed specifically for the  purpose.  
  159. However, the examples in this article should illustrate that the time 
  160. you spend exploring PC-DOS can be well worthwhile.  
  161.  
  162. Figure 1: After running FUNKEY, the following PC-DOS 2.0 commands are 
  163. assigned to the ten function keys.  F1 to F10 are the input file names 
  164. of the function keys in their normal state; C1 to C10 are the names for 
  165. the keys in combination with the Control Key.
  166.                F1 = A:                  C1 = MORE
  167.                F2 = B:                  C2 = FIND
  168.                F3 = DIR                 C3 = SORT
  169.                F4 = CHKDSK              C4 = MODE
  170.                F5 = COPY                C5 = PATH
  171.                F6 = ERASE               C6 = TREE
  172.                F7 = TYPE                C7 = MKDIR
  173.                F8 = PRINT               C8 = RMDIR
  174.                F9 = RENAME              C9 = RECOVER
  175.                F10 = CLS                C10 = FORMAT
  176.  
  177. - - - - -
  178. /*     FUNKEY.C - A program for defining function keys  */
  179.  
  180. #define SEQ "\033[0;"   /* initial sequence to ANSI driver */
  181.  
  182. #include "stdio.h"      /* copy in the standard I/O routines */
  183.  
  184. main(argc,argv)
  185. int argc;
  186. char *argv[];
  187.  
  188. {
  189.   FILE *fp, *fopen();
  190.   
  191.   if (argc ==1)
  192.     {
  193.       printf("\nEnter new key definitions\n\n");
  194.       fkey(stdin);        /* get input from keyboard */
  195.     }
  196.   else
  197.     {
  198.       fp = fopen(*++argv,"r");
  199.       fkey(fp);         /* get input from file */
  200.     }
  201. }
  202.  
  203. int count = 0;    /* counter for tracking size of table */
  204.  
  205. fkey(fp)
  206. FILE *fp;
  207. {
  208.   int c,offset;
  209.   /* input character and function key identifier */
  210.  
  211.   while((c=getch(fp)) != EOF)
  212.  {
  213.    switch (c)
  214.    {
  215.     case 'F':             /* F1 through F10 */
  216.       offset = 58;
  217.       func(getch(fp),offset,fp);
  218.       break;
  219.     case 'S':             /* Shift F1 through F10 */
  220.       offset = 83;
  221.       func(getch(fp),offset,fp);
  222.       break;
  223.     case 'C':             /* Control F1 through F10 */
  224.       offset = 93;
  225.       func(getch(fp),offset,fp);
  226.       break;
  227.     case 'A':             /* Atl F1 through F10 */
  228.       offset = 103;
  229.       func(getch(fp),offset,fp);
  230.       break;
  231.     default:
  232.       print("Unknown function key\n");
  233.       break;
  234.    }
  235.   }
  236. }
  237.  
  238. getch(fp)
  239. /* throw away white space until a character */
  240. FILE *fp;
  241. {
  242. int x;
  243.  
  244.   while(x=getc(fp)) ==' '||x=='\n'||x=='\t')
  245.     ; /* ignore while space */
  246.   return(x);
  247. }
  248.  
  249. func(c,offset,fp)
  250. /* send out the required definition sequence */
  251. int c,offset;
  252. FILE *fp;
  253. {
  254.   int x,save;
  255.  
  256.   save = ' ';
  257.   while ((x=getch(fp)) != '=')
  258.     if (x=='0') c=':';
  259.     /* read until get = sign */
  260.     /* if character is 0 then F10 was chosen rather */
  261.     /* rather than F1. Change c so that offset is */
  262.     /* calculated correctly */
  263.    printf9SEQ);
  264.    printf("%d",offset+(c-'0'));
  265.    putchar(';');
  266.    putchar('"');
  267.    while ((x=getc(fp)) != '\n')
  268.     {
  269.     if (x != '!')
  270.      {
  271.       putchar(x);
  272.       if ((count = count+1) ==128)
  273.       {
  274.        printf("\nTable size exceeded. Program terminated...\n");
  275.        exit();
  276.       }
  277.      }
  278.       else
  279.          save = x;
  280.     }
  281.    putchar('"');
  282.    if (save == '!')
  283.      printf(";13p");
  284.    else
  285.       printf(";32p");
  286.    save = ' ';
  287.    if ((count=count+1) == 128)
  288.    {
  289.    printf("\nTable size exceeded. Program terminated...\n");
  290.    exit();
  291.    }
  292. }
  293. /*  End of listing   */
  294. -----------------------------------------------------------------
  295.          Further to "Defining Functions Keys with PC-DOS 2.0"
  296.             (PC Magazine Vol 2 No 4 Sept 1983 User-to-User)
  297.  
  298.      The article, "Defining Functions Keys with PC-DOS 2.0," mentioned 
  299. that the Keyboard Key Reassignment (KKR) escape sequence had an 
  300. undocumented limit of 128 bytes in its lookup table.  The actual table 
  301. limit is 190 bytes.  The table, used to store the key redefinitions, 
  302. contains a  1-byte length code followed by the string between the Esc [ 
  303. and the p delimiters for each key redefinition.  For example, the 
  304. sequence:
  305.           Esc [0;68;"dir";13p
  306. would be stored as the hex string, 07 00 44 64 69 72 13.
  307.      The DEBUG procedure shown below creates a copy of ANSI.SYS with a 
  308. larger lookup table.  For ease in calculating the required numbers, I 
  309. would recommend enlarging the table by a multiple of 80H bytes.
  310.      The expressions given in parentheses should be calculated and 
  311. placed in the command without parentheses.  The length the table is 
  312. extended is shown as xxxH.  The numbers I used for enlarging my KKR 
  313. lookup table by 200H bytes are shown near the right margin.  My 
  314. comments are in brackets.  
  315.      First make a copy of ANSI.SYS.  Do not modify your original copy.
  316.           COPY ANSI.SYS ANSIX.SYS
  317. Then enter DEBUG ANSIX.SYS and follow the rest of the procedure shown 
  318. below.
  319.      The entry in CONFIG.SYS should now be changed to DEVICE=ANSIX.SYS 
  320. and the system rebooted.
  321.      A command file ANSIX.CMD to be used as redirected input to DEBUG 
  322. is shown here.  The lines changing the CS and DS registers must, of 
  323. course, be changed to match your system.  My CS on entry to DEBUG was 
  324. A8A and I made ANSIX.SYS 200H bytes longer.  Execute as:  DEBUG 
  325. ANSIX.SYS < ANSIX.CMD.
  326.  
  327. r
  328. r cs
  329. a9a
  330. f ds
  331. a9a
  332. rcs
  333. 880
  334. a cs:12
  335. dw 809
  336. a cs:4ff
  337. mov cs,809
  338. a cs:530
  339. cmp bx,2c8
  340. f cs:680 87f 0
  341. m cs:600 67f 800
  342. f cs:600 67f 0
  343. a cs:842
  344. mov word ptr [bx+0e],809
  345. a cs:84a
  346. jmp 0de
  347. r cs
  348. a8a
  349. r ds
  350. a8a
  351. w
  352. q
  353.  
  354. This change allows a more reasonable KKR sequence to be defined.
  355.      The DEBUG procedure that creates a copy of ANSI.SYS with a larger 
  356. lookup table:
  357.  
  358. DEBUG ANSIX.SYS                {The program will be loaded at
  359.                                 CS:100}
  360. R                              {Determine current CS, DS and
  361.                                 CX}
  362. R CS
  363. (old CS + 10H)                 {Compensates for the load      A9A
  364.                                 offset}
  365. R DS
  366. (old CS + 10H)                 {Compensates for the load      A9A
  367.                                 offset}
  368. R CX
  369. (old CX + xxxH)               {Sets file length to be       880
  370. A CS:12                         written}
  371. Dw(609H + xxxH)                {Fix pointer to initializa-    809
  372.                                 tion}{Return to end assembly}    
  373. A CS:4FF
  374. MOV CX,(609H + xxxH)           {Pointer to initialization}    809
  375.                                {Return to end assembly}
  376. A CS:530
  377. CMP BX,(OC8H + xxxH)           {Table length}                 2C8
  378.                                {Return to end assembly}
  379. F CS:680 (67FH + xxxH) 0       {Fill extended table with      87F
  380.                                 zeros}
  381. M CS:600 67F (600H + xxxH)     {Move initialization code}     800
  382. F CS:600 67F 0                 {Zero old unit code location}
  383. A CS:(642H + xxxH)             {Fix pointer to initializa-    842
  384. MOV WORD PTR [BX + 0E],(609H + xxxH)                  tion}   809
  385.                                {Return to end assembly}
  386. A CS:(64AH + xxxH}             {Fix jump to main code}        84A
  387. JMP 0DE
  388.                                {Return to end assembly}
  389. RCS                            {Restore original CS}
  390. (CS: as it was on entry to debug)                             A8A
  391. RDS                            {Restore original DS}
  392. (DS: as it was on entry to debug)                             A8A
  393. W                              {Write the new file}
  394. Q                              {Quit debug}
  395. -----------------------------------------------------------------
  396.                              Changing Keys
  397.             (PC World Vol 2 No 3 March 1984 by Brian Mann)
  398.  
  399.      One reason the PC is so versatile is that you can define not only 
  400. its function keys but also its standard keys.  The definition process
  401. is somewhat complicated, particularly when the escape code (ASCII 27)
  402. is required.  This character is interpreted as an "erase line" command,
  403. and care must be taken when including it not to inadvertently destroy
  404. code or text.
  405.      Another problem is reassigning keys back to their original DOS 
  406. definitions.  It is often necessary to reassign key values so that 
  407. other programs, such as the IBM Personal Editor, can define keys for 
  408. their own purposes.  By studying Chapter 13 in the DOS 2.0 manual, 
  409. "Using Extended Screen and Keyboard Control," and using the DOS batch 
  410. file in this article, problems with assigning and reassigning keys can
  411. be avoided.
  412.      Before the assigned key definitions, including those for the 
  413. function keys, can be changed the ANSI driver must be resident in the 
  414. PC.  First, a CONFIG.SYS file containing the statement DEVICE = 
  415. ANSI.SYS must be created on the boot disk.  The CONFIG.SYS file will, 
  416. among other things, install a program that is not "native" to DOS -- in 
  417. this case, the ANSI driver.  The ANSI.SYS file, which is included on
  418. the DOS 2.0 disk, must also be on the boot disk.  To create this file, 
  419. first place the boot disk in drive A. At the DOS A> prompt, type 
  420. COPY.CON:CONFIG.SYS and then press <Enter>.  Type DEVICE = ANSI.SYS and 
  421. press <Enter>.  Finally, press <F6> (or <Ctrl-Z) and press <Enter>.
  422.      The CONFIG.SYS file is automatically read only when the PC is 
  423. turned on or restarted with the <Ctrl>-<Alt>-<Del> sequence.  A disk 
  424. containing CONFIG.SYS must be in drive A before any keyboard 
  425. reassignment program can be run.
  426.      Using an editor such as EDLIN, enter the batch program KEYS.BAT 
  427. (see Listing 1) onto a disk in drive A.  If you have an emulated disk 
  428. drive, operation will be faster if you copy KEYS.BAT there.  If you 
  429. enter KEYS ON from DOS, the program will execute and define the keys 
  430. you specify.  If you enter KEYS OFF, the keys will return to their 
  431. original DOS definitions.
  432.      The first line in KEYS.BAT illustrates the undocumented fact that 
  433. DOS treats a statement beginning with a period as a comment.  The 
  434. second line turns ECHO off so DOS won't display the KEYS.BAT statements 
  435. as they execute.  The "%1" used in the next four statements is equal to 
  436. the parameter entered after the file name.  In other words, when KEYS 
  437. ON is entered, KEYS.BAT is loaded and "%1" is set equal to "on".  The 
  438. statements determine what "%1" is equal to ("ON", "on", "OFF', or 
  439. "off") and jump to the proper label, either ":ON" or ":OFF", or to 
  440. ":END" if no value is set equal to "%1".  Next, ECHO is turned back on.  
  441. ECHO must be on so that the following key assignments accomplished via 
  442. the DOS command PROMPT will work.
  443.      The PROMPT command is often used to change the standard DOS 
  444. prompt.  For example, PROMPT = WHAT NEXT? would cause DOS to display 
  445. WHAT NEXT? as a DOS prompt instead of A>.  In KEYS.BAT the PROMPT 
  446. command issues an escape code (ASCII 27) with the symbol "$e"; this
  447. code is necessary when ANSI.SYS is used to define the keys.
  448.      Keys are defined in the first section of the batch file following 
  449. the ":ON" label.  If an automatic return is desired, the definition 
  450. should be followed by ";13p"; if no return is desired, a "p" should be 
  451. used.
  452.      Almost any key's value may be redefined.  In order to change a 
  453. key, the ASCII code representing that key must be sent to the ANSI 
  454. driver via a special escape sequence.  The ASCII codes of standard keys 
  455. such as the A or backslash keys are only one character long, and a 
  456. sequence would look like:
  457.           prompt=$e[50;"definition "p
  458. The PC has an extended set of ASCII codes to represent the special keys 
  459. on the keyboard.  The special keys (mostly function keys and keys 
  460. shifted using Alt or Ctrl) are two characters long and are prefaced by
  461. a zero and a comma.  A sequence would look like:
  462.           prompt=$e[0;59;"DIR "p
  463.      But how are original DOS definitions restored?  To understand the 
  464. process, the role of the ANSI driver must be considered.
  465.      The letter A is not sent to the computer when you press the A key.  
  466. Neither is the ASCII code of the letter sent, but rather a scan code 
  467. determined by the location of the key.  The ANSI driver, which can be 
  468. imagined as a box between the keyboard and the PC, intercepts the scan 
  469. code sent by the keyboard and compares it against a reassignment list.  
  470. If the key has not been reassigned, the ANSI driver converts the scan 
  471. code to the proper ASCII value and sends it to the PC.  If the key has 
  472. been reassigned, the ANSI driver sends out the character string that 
  473. was given to the key.
  474.      Restoring a key to its original DOS value involves writing over 
  475. the last key definition.  For example, the first prompt statement in 
  476. Listing 1 following the ":ON" label (prompt=$e[0;59; "DIR "p) tells the 
  477. ANSI driver to send out DIR when it intercepts the ASCII code.  The 
  478. first prompt line after the ":OFF" label (prompt=$e[0;59;0;59p) tells 
  479. the ANSI driver to send out 0;59 when it intercepts the ASCII code.  
  480. The computer is not aware that the ASCII code was ever intercepted and 
  481. applies the original DOS definition (0;59) to the key.  In reassigning 
  482. the original definitions, it is not necessary to include an automatic 
  483. return.
  484.      In Listing 1 the Alt-1 combination (ASCII code 0;120) issues the
  485. command A:KEYS ON, and the Alt-0 combination (ASCII code 0;129) issues
  486. the command A:KEYS OFF.  These definitions are not changed by the KEYS
  487. OFF command, since the above ASCII codes do not appear below the ":OFF"
  488. label.  Once KEYS ON is executed, pressing Alt-0 returns the keyboard
  489. to the original DOS definitions; Alt-1 reassigns the keyboard.
  490.      After the reassignments or original assignments are made, KEYS.BAT 
  491. jumps to the ":END" label, which sets the prompt back to A>.  If 
  492. execution is aborted by Ctrl-Break, the prompt will not appear, and 
  493. "prompt=$n$g" must be entered to return the prompt to the screen.
  494.      Keys may be defined as desired, but there is a catch.  If you 
  495. exceed 190 characters of ANSI driver definitions, the COMMAND.COM file 
  496. next to the ANSI driver on the disk is likely to be overwritten.  The 
  497. computer will freeze up, and you will be forced to turn it off and 
  498. start all over.
  499.      Using the PROMPT command will sometimes produce an "Out of 
  500. environment space" error message.  This will not freeze up the 
  501. computer, but it will prevent key redefinition.  The environment, as 
  502. defined by DOS 2.0, is a place where the operating system puts 
  503. information so other programs can access it.  (This is not the same as 
  504. the ANSI definition space discussed above.)  Issuing the command SET 
  505. from DOS will display the environment, for example:
  506.           COMSPEC =
  507.           A:\COMMAND.COM
  508.           PATH = A:B:C:
  509.           PROMPT = $n$g
  510.      When the PC is started, 128 bytes are allocated to the 
  511. environment.  If more space is needed, DOS will attempt to acquire more 
  512. space.  If a resident program, such as MODE, PRINT, or GRAPHICS has 
  513. been executed, space is not available and the "Out of environment 
  514. space" error message will show up.  In the case of KEYS.BAT, the error 
  515. message occurs when a large PROMPT statement is put into the 
  516. environment after a resident program has been run.
  517.      There are two solutions to the problem.  You can include key 
  518. definitions in an AUTOEXEC.BAT file before any resident programs are 
  519. run (see Listing 2).  The second method is more complicated but may be 
  520. superior.  If you have an editor that permits use of the escape code 
  521. (ASCII 27), read the KEYS.BAT file into the editor, remove the
  522. "prompt=$n$g" statement after the ":END" label, and replace all 
  523. occurrences of "prompt=$e" to ECHO followed by your editor's code for 
  524. Escape.  The ECHO statement prints the key definition text; this 
  525. circumvents the prompt statement and the alteration of the environment 
  526. altogether.
  527. - - - - -
  528. Listing 1: KEYS.BAT
  529.  
  530. echo off
  531. if %1 == ON goto ON
  532. if %1 == on goto ON
  533. if %1 == OFF goto OFF
  534. if %1 == off goto OFF
  535. goto END
  536. :ON
  537. echo on
  538. prompt=$e[0;59;"DIR "p
  539. prompt=$3[0;60;"TYPE "p
  540. prompt=$e[0;61;"COPY "p
  541. prompt=$e[0;62;"ERASE "p
  542. prompt=$e[0;63;"A: "p
  543. prompt=$e[0;64;0;64p
  544. prompt=$e[0;65;"B: "p
  545. prompt=$e[0;66;"C: "p
  546. prompt=$e[0;67;"D: "p
  547. prompt=$e[0;68;"A:BASICA ";13p
  548. prompt=$e[0;120;"A:KEYS ON";13p
  549. prompt=$e[0;129;"A:KEYS OFF";13p
  550.      .The Function Keys have been defined 
  551. goto END
  552. :OFF
  553. echo on
  554. prompt=$e[0;59;0;59p
  555. prompt=$e[0;60;0;60p
  556. prompt=$e[0;61;0;61p
  557. prompt=$e[0;62;0;62p
  558. prompt=$e[0;63;0;63p
  559. prompt=$e[0;64;0;64p
  560. prompt=$e[0;65;0;65p
  561. prompt=$e[0;66;0;66p
  562. prompt=$e[0;67;0;67p
  563. prompt=$e[0;68;0;68p
  564.      .The Function Keys have been disabled 
  565. :END
  566. prompt $n$g       (End of KEYS.BAT)
  567. - - - - -
  568. Listing 2: Example AUTOEXEC.BAT file
  569.  
  570. echo off
  571. date
  572. time
  573. echo on
  574. prompt=$e[0;59;"DIR "p
  575. prompt=$e[0;60;"TYPE "p
  576. prompt=$e[0;61;"COPY "p
  577. prompt=$e[0;62;"ERASE "p
  578. prompt=$e[0;63;"A: "p
  579. prompt=$e[0;64;0;64p
  580. prompt=$e[0;65;"B: "p
  581. prompt=$e[0;66;"C: "p
  582. prompt=$e[0;67;"D: "p
  583. prompt=$e[0;68;"A:BASICA ";13p
  584. prompt=$e[0;120;"A:KEYS ON";13p
  585. prompt=$e[0;129;"A:KEYS OFF";13p
  586. (The Function Keys have been defined)
  587. prompt $n$g
  588. echo off
  589. mode 80
  590. veify on
  591. graphics
  592. cls
  593. ver
  594. vol a:           (End of AUTOEXEC.BAT)
  595.  
  596. -----------------------------------------------------------------
  597.                Assigning Strings to Keys with PC-DOS 2.0
  598.           (PC Magazine Vol 2 No 6 Nov 1983 by Gregg Weissman)
  599.  
  600.      The manual for PC-DOS 2.0 mentions that you can assign any 
  601. character string to any of the keys on the IBM PC's keyboard.  You
  602. could create command lines and text that can be called up with single 
  603. keystrokes from DOS, just as can be done from BASIC.  However, the 
  604. manual is sketchy.  There is a limit to the total number of characters 
  605. that can be assigned to the keyboard in this way -- the computer will 
  606. crash if you try to exceed this quota.  If you're adventurous and 
  607. somewhat familiar with DEBUG, you might follow my additional 
  608. instructions to increase the maximum number of characters allowed while 
  609. implementing a key-assignment scheme.
  610.      The portion of an operating system that controls input from the 
  611. keyboard and output to the screen is called the device driver because 
  612. it controls those devices.  DOS has been designed to allow you to 
  613. easily replace those drivers with others.  In the following case, the 
  614. normal keyboard/screen input/output program (the Console device driver) 
  615. will be replaced with the ANSI.SYS device driver.  This extended 
  616. program contains the logic for detecting and acting upon the special 
  617. sequences of characters known as escape sequences, so-called because 
  618. they all begin with ASCII 27 decimal, which stands for Escape.  The
  619. escape sequences translate into the key assignments you wish to make.
  620.      The first step is to get the ANSI.SYS program loaded into the 
  621. computer by creating a configuration file called "CONFIG.SYS" which 
  622. will tell the operating system what to do with itself.  If the 
  623. statement "DEVICE=ANSI.SYS" appears in the CONFIG.SYS file, DOS will 
  624. load ANSI.SYS in place of the standard keyboard/screen console device 
  625. driver.   
  626.      If you'd like to see this information in action, type in the 
  627. following two lines to copy a CONFIG.SYS file to your disk:
  628.           COPY CON: C:\CONFIG.SYS
  629.           DEVICE=ANSI.SYS
  630. (In the first line, "C:" is the label for the fixed hard disk.  If you 
  631. want to use a different disk drive, substitute the appropriate label.)  
  632. After entering the second line, press F6 and then the Return key.
  633.      Now the extended console driver will be loaded from disk when the 
  634. operating system starts.  If this is the first time you have included 
  635. the CONFIG.SYS file and the "DEVICE=ANSI.SYS" command, first reset the 
  636. computer so that DOS can load up the ANSI program; otherwise the 
  637. examples in the article won't work.
  638.      The next thing that happens after the ANSI.SYS is loaded is that 
  639. DOS "calls" an initialization routine within the driver; DOS asks the 
  640. driver to set itself up (as it were) and return an address that is the 
  641. last memory location the ANSI.SYS driver will occupy.  DOS needs to 
  642. know how big the driver is, so it can utilize the memory above it for 
  643. other functions.  In its present, unmodified state, the ANSI driver 
  644. returns an address that allows space for 200 of your defined character 
  645. strings in addition to the program itself.
  646.      Once this initialization is complete, DOS goes about its business, 
  647. which normally has nothing to do with getting special things to happen 
  648. when keys are pressed. 
  649.      The way that you assign a string to a key on the keyboard is 
  650. simpler than it may appear in the DOS manual.  All you need to do is 
  651. send a sequence of characters to CON, which is the driver for the 
  652. keyboard/screen console driver.  Ultimately, this can be done either by 
  653. sending the appropriate data to the CON device with the COPY command or 
  654. by TYPEing the appropriate file.  Either way, as long as the file 
  655. contains the proper sequence of characters, the driver will interpret 
  656. the file as key assignments (the file can also provide screen controls, 
  657. but that should be the subject of another article).  Instead of having 
  658. any text appear on the screen, as would normally happen when you TYPE a 
  659. file to the console, the keys you specify in the file will be set up 
  660. to return the string you assigned to them.
  661.      The form of the escape sequence that will cause the ANSI.SYS 
  662. driver to assign text to a key is also simple.  The first character 
  663. must be the Escape character (ASCII 27).  (This would be CHR$(27) in
  664. BASIC; in hexadecimal, the value is 1B.)  When the ANSI driver sees you
  665. trying to print the character with a value of 27 decimal, it prepares
  666. itself to respond to subsequent characters not as characters to be
  667. printed to the screen, but as codes that you wish to be interpreted for
  668. you.  The next character must be a left bracket, ([) (ASCII 91 or 5B
  669. hex).  Once the driver has detected the Escape character, nothing will
  670. happen until it next detects the left bracket.
  671.      Up to this point, the driver has seen the Escape character and the 
  672. left bracket, and is prepared to interpret the remainder of the command 
  673. sequence either as numeric values (represented by ASCII text digits) of 
  674. as literal characters.  In the first case, the driver interprets ASCII 
  675. digits "0" thru "9", and calculates a binary value for the represented 
  676. digits.  If the driver is sent the ASCII value for 9, the program 
  677. calculates 19 decimal.  If ASCII codes for 1, 2, and then 0 are sent, 
  678. the resulting ASCII value is 120 decimal, and so on.  The program 
  679. continues to receive and calculate until it detects a semicolon 
  680. character (ASCII value 3B hex), which serves to tell where one number 
  681. leaves off and another one begins.
  682.      In the "1,2,0" example above, the command would mean that you are 
  683. telling the program to reassign the key that sends out the ASCII code 
  684. 120 decimal when it is pressed.  What is going on is that you are using 
  685. ASCII codes for digits to represent the decimal value of another ASCII 
  686. code that the keyboard sends out.  If you were to look at the 
  687. hexadecimal representation of the sequence so far, just as the ANSI 
  688. driver receives them, it would look like this:
  689.  
  690.                1B     5B  31  32  30  3B  
  691.             <Escape>   [   1   2   0   ;
  692.  
  693.      Now, if you send a single or double quote mark to the driver, it 
  694. will store the next sequence of characters into memory as is, to be 
  695. sent out later as a string of text whenever it detects key 120 decimal 
  696. (which is lowercase "x").
  697.      Say you wish to have the computer spell out "EXAMINE" whenever 
  698. you press lowercase "x".  Your next command sequence would then be: 
  699. <ASCII quote-mark> EXAMINE <ASCII quote-mark>, followed by another 
  700. semicolon, then a lowercase p (p is the "Yes, I really meant that; now 
  701. do it!" command to the driver program).
  702.      The following procedure demonstrates how you could assign a string 
  703. to a key by using the DEBUG program.  Assume the same conditions as 
  704. before; that is, you wish to have the computer type the word "EXAMINE" 
  705. when you press the lowercase x key.  You must use the DEBUG program at 
  706. this point because you can't enter the Escape character from the 
  707. keyboard.  Under DOS, the Escape key is interpreted as "cancel the 
  708. input line."  A little later I will show a BASIC program that will 
  709. automate all this, but for now, from DOS, start the DEBUG program by 
  710. typing "DEBUG".
  711.      When you see the dash prompt (-), DEBUG is ready to use.  Type 
  712. this line as it appears, quotes and all.  (The 22 that you type on 
  713. either side of "EXAMINE" is the ASCII hex value of a double quote 
  714. mark.)
  715.           E 100 1B "[120;"22"EXAMINE"22"p"
  716. Then press the Return key.  What you did was to give the Enter command 
  717. (e), then the required sequence was entered directly into memory.  Now 
  718. type D100 and press return.  Look at the hexadecimal values on the 
  719. first line at the left of the screen; they should look familiar:
  720.           1B 5B 31 32 30 3B
  721. Now look to the right of the screen; you should see:
  722.           .[120;"EXAMINE";
  723. Perhaps the result is a little clearer in this form.
  724.      Pressing the lowercase x key will return the ASCII value 120; that 
  725. value is looked up by the console driver, and the associated string 
  726. "EXAMINE" is printed out.  Before this will work, however, you must 
  727. write the little file you created onto the disk.  To do so, type R CX 
  728. and press Return.  When you see the prompt, key in 10 and press Return; 
  729. then type N KEYX.ANS and press Return to give the file the name 
  730. KEYX.ANS.  If you want to save the file on a different disk, type a 
  731. drive designation before the file name; for example, you could key in N 
  732. B: KEYX.ANS to assign the file to the B drive.
  733.      After naming the file, press the W key and then Return.  The 
  734. computer will respond with the message "Writing 10 bytes."  When that 
  735. process is over, press the Q key and then Return to exit from DEBUG.  
  736. Check the disk directory to verify that the new file called KEYX.ANS is 
  737. actually saved on the disk.  Then type:
  738.           COPY KEYX.ANS CON:
  739. and press Return.  (If you had put KEYX.ANS on another drive, make sure 
  740. to include the drive's name here.)  When you do this, nothing should 
  741. happen except that the message "1 File(s) copied" and the DOS prompt 
  742. will appear.
  743.      Now type a lowercase x, and see what happens.  If "EXAMINE" didn't 
  744. appear on the screen, either the ANSI.SYS console driver hadn't been 
  745. installed (see the beginning of this article) or you keyed in something 
  746. incorrectly.  Try again after making sure the device driver is 
  747. installed.  Another more effective and rapid solution is that the
  748. entire keyboard can be defined by running a BASIC program that writes
  749. the control codes to a sequential disk file, which you can then TYPE or 
  750. COPY to the console driver.  First another word on the ASCII values.
  751.      It would be nice if we could leave the standard key definitions 
  752. as they are, and assign special character strings only to the functions 
  753. keys of Alt keys.  The way to do this is to define the first number 
  754. sent after the Escape and left bracket characters as ASCII value zero; 
  755. this is followed by the semicolon, the actual "extended ASCII code" for 
  756. the key desired, and finally the string assignment itself.  You can use 
  757. all the function keys in the standard, Shift, Ctrl, or Alt modes; 
  758. actually 40 different codes can be assigned to the function keys.  In 
  759. addition, all the alphanumeric keys can be used in the Alt mode, 
  760. including such keys as Home and End.  However, this vast versatility is 
  761. limited by the 200-character limit imposed by the unmodified ANSI 
  762. driver.
  763.      Figure 1 is a simple BASIC program that could be used to let you 
  764. go through the ten function keys, one at a time, and assign a different 
  765. string to each one.  When the BASIC program finishes and saves the 
  766. KEYS.ANS file to disk, you can enter DOS, they type the file in order 
  767. to effect the key assignments.
  768.      If you avoided the 200-character limit by being conservative with 
  769. the length of strings you assigned to the function keys, you should now 
  770. be able to return to DOS from BASIC by typing SYSTEM, then COPY the 
  771. KEYS.ANS file to CON by entering:
  772.           COPY KEYS.ANS CON:
  773. If the computer hangs up, just reboot to start from scratch with DOS 
  774. and trim down your string assignments.
  775.      Figure 2 shows the key assignment program in use.  If you succeed 
  776. in assigning strings to your function keys, but get tired of that set 
  777. of tricks, you can eliminate the key assignments by rebooting the 
  778. system.  You can also run the BASIC program again to input blank "null 
  779. strings" that eliminate the key assignments.
  780.  
  781. - - - - -
  782. Figure  1:  A  BASIC  program that prompts a  user  to  assign  strings             
  783. to the ten function keys.
  784.  
  785. 10 DEFINT I-Z:DEFSTR A-H
  786. 20 DIM ANSI.KEY(10)
  787. 30 FOR I=1 TO 10
  788. 40 ?"KEY NUMBER";I;"STRING";:INPUT ANSI.KEY(I)
  789. 50 NEXT
  790. 60 REM This is an admittedly oversimplified input routine.
  791. 70 OPEN "0",#1,"KEYS.ANS"
  792. 80 FOR I=1 TO 10
  793. 90 ASKEY.CODE=MID$(STR$(58+I),2)
  794. 100 REM Line 90 strips off the leading blank from the string.
  795. 110 PRINT #1,CHR$(27)"["0;"ASKEY.CODE";"CHR$(34);ANSI.KEY(I); 
  796. CHR$(34)"p";
  797. 120 REM Note the trailing semicolon at the end of line 110
  798. 130 NEXT
  799. 140 CLOSE
  800. 150 END
  801. - - - - -
  802. Figure 2: A demonstration of using the program in Figure 1.
  803.  
  804.      I wanted to be able to press any of the ten function keys and have 
  805. the French word for its number appear on the screen.  I ran the BASIC 
  806. program in Figure 1 and keyed in the lowercase words in response to the 
  807. prompt on each line.
  808.  
  809.           KEY NUMBER 1 STRING? un
  810.           KEY NUMBER 2 STRING? deux
  811.           KEY NUMBER 3 STRING? trois
  812.           KEY NUMBER 4 STRING? quatre
  813.           KEY NUMBER 5 STRING? cinq
  814.           KEY NUMBER 6 STRING? six
  815.           KEY NUMBER 7 STRING? sept
  816.           KEY NUMBER 8 STRING? huit
  817.           KEY NUMBER 9 STRING? neuf
  818.           KEY NUMBER 10 STRING? dix
  819.  
  820.      After entering the string for F10, I was returned to DOS.  I then 
  821. saved the file of key assignments by entering the following after the 
  822. prompt:
  823.           C> COPY KEYS.ANS CON:
  824.      The computer responded with "1 File(s) copied" and another prompt.  
  825. Following this prompt, I pressed each of the function keys and the 
  826. French names of the numbers appeared.
  827.           C> un deux trois quatre cinq six sept huit neuf dix
  828.      When I pressed Return again, the screen read "Bad command or file 
  829. name".
  830.  
  831. -----------------------------------------------------------------------
  832.                  Modifying the ANSI.SYS Console Driver
  833.          (PC Magazine Vol 2 No 6 November 1983 by G. Weissman)
  834.  
  835.      If you now understand how to assign strings to key, and if you are 
  836. familiar with the DEBUG program, you may want to take this next step -- 
  837. modifying the ANSI.SYS file to allow longer strings and more keys to be 
  838. assigned.  But beware: this can get tricky.  If you're not comfortable 
  839. with messing around in machine-language files, go very slowly.  And, 
  840. although this procedure seems to work okay on my version of DOS 2.0, I 
  841. can give you no guarantees.
  842.      The first thing to do if you undertake this project is to make a 
  843. backup copy of the file called ANSI.SYS.  To be on the safe side, you 
  844. may want to modify this file on a separate disk before modifying the 
  845. hard disk's system files.  It would be a funny feeling to have 2.5 
  846. megabytes of valuable data refuse to boot.  Have the CONFIG.SYS file 
  847. set up to load the ANSI.SYS file, as explained in the earlier 
  848. procedure, by keying in these two lines:
  849.           COPY CON: C:\CONFIG.SYS
  850.           DEVICE=ANSI.SYS
  851. After entering these two lines, press F6 and then Return.
  852.      You should find it helpful to obtain a disassembly of the ANSI.SYS 
  853. file from the debugger.  To obtain the listing, press Ctrl-PrtSc, then 
  854. call up DEBUG along with the name of the file by entering DEBUG 
  855. ANSI.SYS.  Then type U 1A2 750, press Return, and take a break until 
  856. the disassembly prints out. It would be a good time to read the rest of 
  857. the procedure.  I assume you have the DOS 2.0 DEBUG program that allows 
  858. you to assemble simple commands directly into memory.  If you don't 
  859. have 2.0, I doubt you can do any of this.
  860.      Four changes have to be made to the program: 1) the initialization 
  861. procedure has to return a higher ending address to DOS upon completion 
  862. of initialization; 2) the maximum value test for the total number of 
  863. characters assigned to keys must be increased; 3) the initialization 
  864. procedure must be actually moved to make the necessary room and pointed 
  865. to within the device driver itself; and, 4) a new end-of-buffer-value 
  866. loaded into the CX register must be altered to conform with our 
  867. changes.
  868.      The first step is to move the initialization code up by 300 hex 
  869. bytes, using the "M" command.  It might be a good idea to keep the 
  870. Ctrl-PrtSc printing turnd on to maintain a log of what you do here in 
  871. case there are problems.  You can refer to the printout later and check 
  872. your work.
  873.      Look at the listing from 0709 to 074D.  This is the initialization 
  874. code that we will move.  Type M 709 750 A09 and press Return.  You have 
  875. just moved the code up 768 bytes, enough for many more keys to be 
  876. assigned.  But now we must compensate.  Look on the screen to find the 
  877. disassembly at 0A42.  It reads:
  878.           MOV WORD PTR [BX+0E],0609"
  879. This is the code that tells DOS that it can have back everything from 
  880. 0609 hex on, relative to offset 0 in the segment where the device 
  881. driver is loaded.  The code you are seeing now has an offset of 100 
  882. hex added to it by the debugger.  In DOS now, the code you moved from 
  883. 0709 is actually located at offset 0609; this is precisely where the 
  884. driver released its claim on memory.  We have to add 300 hex to the 
  885. value passed to DOS as well.  You may use either the "A" command or the 
  886. "E" command to change the value "0909" (not 0A09 -- remember the 100 
  887. byte offset from the debugger?)
  888.      To use the "A" command to assemble a new instruction, enter these 
  889. two lines:
  890.           A 0A42
  891.           MOV WORD PTR [BX+0E],0909
  892. To use the "E" command, enter this line:
  893.           E 0A46 09
  894.      Either method has the same result.  Next, look at the code on the 
  895. screen at location 0A4A.  It reads "JMP 04DE".  Use the "A" command and 
  896. change that by entering these two lines:
  897.           A 0A4A
  898.           JMP 01DE
  899.      This compensates for the jump forward of 300 hex bytes, as JMP 
  900. instructions are calculated as an offset from the current instruction 
  901. (more or less).  That's why you effectively subtracted 300 from the JMP 
  902. offset using the "A" command.  (A good exercise would be to try using 
  903. the "E" command to directly input the recalculated offset that must be 
  904. added to the location counter so that you land in the right spot.)
  905.      Does everything seem all right so far?  Double check!  One slipped 
  906. bit is all it takes.
  907.      Next, just for cosmetics, fill the locations once used by the 
  908. initialization routine (and any other garbage that was lying around in 
  909. the computer in between the old and new initialization routines) with 
  910. zeros, so that the keystring buffer loads up empty.  Use the "F" 
  911. command by entering:
  912.           F 0709 0A00 00
  913.      Now use the "D" command to look at the "device driver header" up 
  914. at offset 100.  Start by keying in D100. (Look on the screen, as you 
  915. didn't print out this portion.)  Specifically, look at offset 0112.  
  916. Two consecutive memory locations should read: "09 06".  This was the 
  917. offset from 0 of the initialization routine.  Change the byte at 0113 
  918. to 09 by entering:
  919.           E 113 09
  920.      The offset is now that of the relocated initialization code.  
  921. Remember that the offset will be 100 hex less than the offset you see 
  922. in DEBUG. 
  923.      You can increase the limit on the number of stored characters, 
  924. now that there's room for them.  Look at the code at 0630.  It reads: 
  925. "CMP BX,00C8".
  926.      By using the "A" command again, you can enter a nice round figure 
  927. like, say 02C0; this would raise the maximum number of allowed 
  928. characters to 704.  (I like to leave a lot of leeway here until the 
  929. crash problem is solved, but theoretically you should be able to use 
  930. all the memory from 541 to 0909 -- a total of 3C8 hex bytes, or 968 
  931. decimal.)  To do this, enter these two lines:
  932.           A 630
  933.           CMP BX,02C0
  934.      We're almost finished now. Look at the code at address 05FF.  It 
  935. reads "MOV CX,0609".  That number seems familiar, as it is the offset 
  936. to the old initialization routine, and it appears at the end of the 
  937. keystring buffer.  You have to preserve the same offset relations with 
  938. the other changes made, so change the code at 05FF to read "MOV 
  939. CX,0909" by entering these two lines:
  940.           A 05FF
  941.           MOV CX,0909
  942.      The changes to code are now complete! One final step.  We have to 
  943. write the debugged file to disk, but the size of the file must be 
  944. increased to take into account the expanded buffer and relocated 
  945. initialization code.  Type R CX.  The computer should respond with "CX 
  946. 0680".  You should now enter 980.  Your ANSI.SYS file will not be 768 
  947. bytes larger.  Enter W and the computer will respond with "writing 0980 
  948. bytes".
  949.      When this is finished, you will have vastly more potential to 
  950. assign strings to the keyboard.  The ANSI.SYS file will load when you 
  951. reset the computer, and you can then test your work.  If anything weird 
  952. happens that didn't happen before you made these changes, double and 
  953. triple check your modifications.  Start from the beginning if 
  954. necessary.  Though the effort may seem great now, afterwards you can
  955. let the computer do some of your typing once you've assigned strings
  956. to keys to your heart's content.  Theoretically, there should be no
  957. limit to the storage space you can add to the key buffer using this 
  958. technique.
  959.  
  960. -----------------------------------------------------------------
  961.                      Creating Keyboard Assignments
  962.          (PC Magazine Vol 3 No 9 May 15, 1984 by Tom Sheldon)
  963.  
  964.      Creating keyboard assignments for DOS 2.x involes the following 
  965. process:
  966.           1. Create a file of the control sequences for changing key 
  967. assignments.
  968.           2. Create a CONFIG.SYS file containing the ANSI.SYS keyboard 
  969. driver.
  970.           3. Reboot the system to load the new driver.
  971.           4. Display the assignment file on the screen to assign the 
  972. keys.
  973.      The first step is the most complex. Section 13 of the DOS manual 
  974. describes the kayboard assignment feature, and page 13-10 gives an 
  975. example of assigning the DIR command to the F10 key:
  976.           ESC {0;68;"dir";13p.
  977.      The 0;68 indicates the location of the F10 key on the keyboard, 
  978. the 0 indicates that the key is an extended key (see page G-6 of the 
  979. BASIC manual) and the 13p is a carriage return.
  980.      The tricky part is getting the escape code into the file without 
  981. actually escaping while doing it.  You can't use the escape key on the 
  982. keyboard.  The process described below uses a dummy character in place 
  983. of the escape code, and then uses DEBUG to replace the dummy code with 
  984. the escape code.  After you've captured the elusive code using this 
  985. method, you can use EDLIN to make multiple copies of the original line 
  986. for other keyboard assignments.
  987.      Create a file called ASSIGN.CDS.  The dummy character will be the 
  988. asterisk.  You need only the first part of the string at this point. 
  989. Enter:
  990.           COPY CON;ASSIGN.CDS
  991.           *[0; <F6> <Return>
  992. Now use DEBUG to fix the file.  Type:
  993.           DEBUG ASSIGN.CDS
  994. Type D, and the first line should look like:
  995. 0952:0100 2a 5b 30 3b 00 00 00 00 00 00 00 00 00 00 00 00 *[0;
  996. The asterisk (hex 2a) must be replaced with hex 1b (escape).  Type E
  997. and the address:
  998.           E0952:0100
  999. The asterisk character appears first.  Type 1b, press Return, type W to 
  1000. write the changes to disk, and then type Q to exit.
  1001.      The next step is to get into EDLIN and finish.  Type:
  1002.           EDLIN ASSIGN.CDS
  1003. For 10 copies of the first line, enter:
  1004.           1, 1, 2, 10c
  1005.      If you list the file, there are 11 lines of escape codes.  The 
  1006. escape code in each line is now ^[. Now you only have to add the rest 
  1007. of the string to each line.  You can use the right arrow key to copy 
  1008. from the template, which is the line above the one being edited.  The 
  1009. first four lines should look like:
  1010.           ^[[0;104;"HELP';13p
  1011.           ^[[0;105;"MENU";13p
  1012.           ^[[0;105;"MM";13p
  1013.           ^[[0;107;"PM";13p
  1014. You may use the remaining lines for your own strings.  The codes for
  1015. the function keys are on page G-6 of the BASIC manual.  Enter 13p at
  1016. the end of each string only if you want a carriage return to be
  1017. executed when you press the assigned function key.  When finished,
  1018. hit E to exit and save the file.
  1019.      Create the CONFIG.SYS file by typing:
  1020.           COPY CON:CONFIG.SYS
  1021.           DEVICE=ANSI.SYS
  1022. Press F6 and Return.  Reboot to load the new driver.  If you created
  1023. the AUTOEXEC.BAT file shown in the main text, the ASSIGN. CDS file will
  1024. be displayed on the screen and the keys will be assigned.  (The main
  1025. text is "Building An Orderly Hard Disk" and appears on p. 269-276; it 
  1026. includes the files referenced in the last couple of paragraphs of this 
  1027. article.)
  1028.